package com.summer.campussct.controller;


import com.summer.campussct.annotation.Permission;
import com.summer.campussct.pojo.dto.RestResult;
import com.summer.campussct.pojo.dto.VehicleQueryParams;
import com.summer.campussct.service.IVehiclePublishService;
import com.summer.campussct.utils.PermissionConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 车辆发布表 前端控制器
 * </p>
 *
 * @author Mr.Chen
 * @since 2024-05-10
 */
@Api(tags = "车辆发布相关API")
@RestController
@RequestMapping("publish")
public class VehiclePublishController {

    @Resource
    private IVehiclePublishService vehiclePublishService;

    @ApiOperation("发布车辆")
    @PostMapping("publishVehicle/{id}")
    public RestResult publishVehicle(@PathVariable("id") long id){
        return vehiclePublishService.publishVehicle(id);
    }

    @ApiOperation("发布之后的车辆修改价格")
    @PutMapping("modifyPrice")
    public RestResult modifyPrice(@RequestParam Long vid,
                                  @RequestParam BigDecimal price){
        return vehiclePublishService.modifyPrice(vid, price);
    }

    @ApiOperation("下架车辆")
    @PutMapping("offlineVehicle/{id}")
    public RestResult offlineVehicle(@PathVariable("id") long id){
        return vehiclePublishService.offlineVehicle(id);
    }

    @ApiOperation(("重新发布车辆"))
    @PutMapping("rePublishVehicle/{id}")
    public RestResult rePublishVehicle(@PathVariable("id") long id){
        return vehiclePublishService.rePublishVehicle(id);
    }

    @ApiOperation("获取最近上新")
    @GetMapping("getNew")
    public RestResult getNewList(){
        return vehiclePublishService.getNewList();
    }

    @ApiOperation("查询分类页数据:根据一级分类id查询二级分类数据及其关联的车辆")
    @GetMapping("getCategoryData/{id}")
    public RestResult getCategoryData(@PathVariable("id") int id){
        return vehiclePublishService.getCategoryData(id);
    }

    @ApiOperation("details页：获取车辆详情")
    @GetMapping("details/{id}")
    public RestResult details(@PathVariable("id") long id){
        return vehiclePublishService.getDetails(id);
    }

    @ApiOperation("list页：分页条件查询")
    @PostMapping("listByCondition")
    public RestResult listByCondition(@RequestBody VehicleQueryParams vehicleQueryParams){
        return vehiclePublishService.listByCondition(vehicleQueryParams);
    }

    /**
     * 获取车辆详情，只有发布状态为已发布才能查到
     * @param id 车辆id，而不是发布表的id
     */
    @ApiOperation("order页：获取车辆详情")
    @GetMapping("orderCar/{id}")
    @Permission(PermissionConstant.LOGIN)
    public RestResult orderCar(@PathVariable("id") long id){
        return vehiclePublishService.orderCar(id);
    }

}